package com.ruoyi.web.dorm.service.impl;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.dorm.entity.DormListEntity;
import com.ruoyi.web.dorm.entity.vo.DormStudentVo;
import com.ruoyi.web.dorm.mapper.DormListMapper;
import com.ruoyi.web.dorm.service.DormListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DormListServiceImpl implements DormListService {
    @Autowired
    private DormListMapper dormListMapper;


    /*
     * 获取宿舍列表
     * */
    @Override
    public List<DormListEntity> getDormList(DormListEntity dormListEntity) {
        return dormListMapper.getDormList(dormListEntity);
    }

    /*
     * 添加宿舍
     * */
    @Override
    public int addDormList(DormListEntity dormListEntity) {
//        String username = SecurityUtils.getLoginUser().getUsername(); //获取创建人的名字 添加进去
//        dormListEntity.setCreateBy(username);
       Long adminId = Long.valueOf(dormListEntity.getNickName());
        dormListEntity.setAdminId(adminId);
        return dormListMapper.addDormList(dormListEntity);
    }

    /*
     * 修改宿舍
     * */
    @Override
    public int updateDormList(DormListEntity dormListEntity) {
        String username = SecurityUtils.getLoginUser().getUsername(); //获取创建人的名字 添加进去
        dormListEntity.setUpdateBy(username);

        if (dormListEntity.getNickName() instanceof String){

        }else {
            Long adminId = Long.valueOf(dormListEntity.getNickName());
            dormListEntity.setAdminId(adminId);
        }
        return dormListMapper.updateDormList(dormListEntity);
    }

    /*
     * 删除宿舍
     * */
    @Override
    public int delDormList(Long id) {
        return dormListMapper.delDormList(id);
    }


    /**
     * 获取宿舍学生
     * @param dormStudentVo
     * @return
     */

    @Override
    public List<DormStudentVo> getDormStudent(DormStudentVo dormStudentVo) {
        return dormListMapper.getDormStudent(dormStudentVo);
    }
}
